home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
oper_sys
/
oasis
/
oasis1-1.lha
/
oasis-1.1
/
parser.h
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-01
|
19KB
|
571 lines
/*==========================================================================*
Oasis Alpha Version 1.1 (C) Copyright 1992 Fah-Chun Cheong
Revised: 5/1/92 by: fcc@eecs.umich.edu and The University of Michigan
------------------------------------------------------------------------
Permission to use, copy, modify, distribute, sell and resell Oasis Alpha
software and its documentation for any purpose and without fee is hereby
granted, provided that the authorship be appropriately credited and
acknowledged, and that the above copyright notice appear in all copies
and both the copyright notice and this permission notice appear in
supporting documentation. The author makes no representations about the
suitability of this software for any purpose. It is provided "as is"
without express or implied warranty. Oasis Alpha is free, caveat emptor!
------------------------------------------------------------------------
To request Oasis Alpha source code: oasis-alpha-request@eecs.umich.edu
To enroll in the mailing list: oasis-alpha-request@eecs.umich.edu
To send bug reports: oasis-alpha-bugs@eecs.umich.edu
To discuss openly all matters Oasis: oasis-alpha@eecs.umich.edu
*==========================================================================*/
#include <strings.h>
#include <ctype.h>
#include <stdio.h>
#define LINESZ 1024
#define NUL 0
#define HEAD 0x0
#define BODY 0x2
#define MASK 0x3
#define NEXT 0x4
#define LAST 0x7fffffff
#define UNDEF 0xffffffff
#define IN 0x0
#define OUT 0x1
#define HI 0x0
#define HO 0x1
#define BI 0x2
#define BO 0x3
#define FF 0x00
#define FB 0x10
#define FU 0x20
#define BB 0x30
#define HI_FF 0x00
#define HI_BB 0x30
#define HO_FF 0x01
#define HO_BB 0x31
#define BI_FF 0x02
#define BI_FB 0x12
#define BI_FU 0x22
#define BI_BB 0x32
#define BO_FF 0x03
#define BO_FB 0x13
#define BO_FU 0x23
#define BO_BB 0x33
#define FALSE 0
#define TRUE 1
#define RELOP 2
#define WAIT 5
#define POST 6
#define CALL 7
#define INVK 8
#define SEND 9
#define AGENT 11
#define OBJECT 12
#define COND 13
#define LIST 14
#define ARRAY 15
#define DOPE 16
#define ITEM 17
#define HANDLE 18
#define META 19
#define AT 20
#define SITE 21
#define VAR 22
#define REF 23
#define FIELD 24
#define INDEX 25
#define EXPR 26
#define FUN 27
#define ANON 28
#define AS 29
#define IS 30
#define TOP 31
#define BOT 32
#define ADD 43
#define SUB 45
#define MUL 42
#define DIV 47
#define REM 37
#define RADD -ADD
#define RSUB -SUB
#define RMUL -MUL
#define RDIV -DIV
#define RREM -REM
#define LLIST -LIST
#define LDOPE -DOPE
#define LVAR -VAR
#define LREF -REF
#define Aoff(atts) (atts ? atts->aoff + 1 : 4)
#define Soff(specs) (specs ? specs->soff + 1 : 1)
#define Coff(conds) (conds ? conds->coff + 1 : 2)
#define Moff(mets) (mets ? mets->moff + 1 : 1)
#define Voff(node) (((Var *) node->this.p)->voff)
#define diff(s1,s2) ( strcmp(s1, s2))
#define same(s1,s2) (!strcmp(s1, s2))
#define seen(l,l2,p,p2) (l == l2 || l > l2 && p >= p2)
#define mode(s,f) ((s | f) & MASK)
#define null(t) (t == Int ? Izero\
:t == Real ? Rzero\
:t == Char ? Blank : Nil)
#define isin(s,f) (mode(s,f) == BI || mode(s,f) == HO)
#define isout(s,f) (mode(s,f) == BO || mode(s,f) == HI)
#define isident(c) (isalnum(c) || c == '_')
#define islast(rs,mo) (!rs->next || rs->next->head->moff != mo)
#define islive(vs,s) (vs->def < s && s < vs->use)
#define isclass(t) (t->tag == AGENT || t->tag == OBJECT || t->tag == COND)
#define ispointer(t) (t->tag == AGENT || t->tag == OBJECT || t->tag == ARRAY || t->tag == LIST)
#define isword(t) (t->tag == INT || t->tag == REAL || t->tag == CHAR)
#define ismeta(t) (t->tag == META)
#define flip(tag) tag *= -1
#define Malloc(x) (x *) malloc(sizeof(x))
#define err0(s) point_error(sprintf(errbuf, s))
#define err1(s,a) point_error(sprintf(errbuf, s, a))
#define err2(s,a,b) point_error(sprintf(errbuf, s, a, b))
#define err3(s,a,b,c) point_error(sprintf(errbuf, s, a, b, c))
#define search_spec(id,ss,l,sz,b,gs,cs,ks,as,ms) if (!lookup_spec(id,ss,l,sz,b,gs,cs,ks,as,ms))\
err1("Unspecified class `%s'", id)
#define search_base(id,bs,l,ms) if (!lookup_base(id,bs,l,ms)) err1("Unspecified base `%s'", id)
#define search_gene(id,gs,go) if (!lookup_gene(id,gs,go)) err1("Unspecified generic `%s'", id)
#define search_cond(id,cs,co) if (!lookup_cond(id,cs,co)) err1("Unspecified condition `%s'", id)
#define search_att(id,l,p,as,ao,t) if (!lookup_att(id,l,p,as,ao,t)) err1("Unspecified attribute `%s'", id)
#define search_met(id,l,p,ms,mo,q,as) if (!lookup_met(id,l,p,ms,mo,q,as)) err1("Unspecified method `%s'", id)
#define clash_spec(id,ss) if (find_spec(id,ss)) err1("Class `%s' already specified", id)
#define clash_gene(id,gs) if (find_gene(id,gs)) err1("Generic `%s' already specified", id)
#define clash_cond(id,cs) if (find_cond(id,cs)) err1("Condition `%s' already specified", id)
#define clash_cst(id,ks) if (find_cst(id,ks)) err1("Constant `%s' already specified", id)
#define clash_att(id,l,as) if (find_att(id,l,PROTECTED,as)) err1("Attribute `%s' already specified", id)
#define clash_met(id,l,ms) if (find_met(id,l,PROTECTED,ms)) err1("Method `%s' already specified", id)
#define clash_arg(id,as) if (find_arg(id,as)) err1("Argument `%s' already specified", id)
#define clash_imp(id,is) if (find_imp(id,is)) err1("Class `%s' already implemented", id)
#define clash_head(id,rs,r) if (find_head(id,rs,r)) err1("Method `%s' already implemented", id)
#define count_genes(gs) if (gs) err0("Missing generics")
#define count_pars(as) if (as) err0("Missing method parameters")
#define count_props(as) if (as) err0("Missing class properties")
#define count_indices(ds) if (ds) err0("Missing array indices")
#define count_sizes(ds) if (ds) err0("Missing array sizes")
#define count_items(sz) if (sz > 0) err0("Missing components in array")
#define count_dims(ds) if (ds && ds->next) err0("Missing dimensions in array")
#define count_gene(gs,l,id) if (!gs && l > 0) err1("Extra generic `%s'", id)
#define count_par(as) if (!as) err0("Extra parameter in method")
#define count_prop(as) if (!as) err0("Extra property in class instance")
#define count_index(ds) if (!ds) err0("Extra index in array")
#define count_size(ds) if (!ds) err0("Extra size in array")
#define count_item(sz) if (sz == 0) err0("Extra component in array")
#define count_dim(ds) if (ds && !ds->next) err0("Extra dimension in array")
#define check_gene(gs,l,id) if (gs && l > 0 && diff(id, gs->name)) err2("Bad generic `%s', expect `%s'", id, gs->name)
#define check_agent(k) if (k != AGENT) err0("Goal clause invalid for object class")
#define check_remote(tag) if (tag != SEND) err0("Concurrent message is to agents only")
#define check_lvalue(tag) if (tag != REF && tag != VAR) err0("Constant does not have lvalue")
#define check_self(n) if (n == Self) err0("Undefined self out of context")
#define get_name(t) (isclass(t) ? t->u.class->name : "")
#define get_cons(t) (isclass(t) ? t->u.class->cons : NUL)
#define get_item(t) (t->tag == ARRAY ? t->u.array->item : Top)
#define get_dims(t) (t->tag == ARRAY ? t->u.array->dims : (Dim *) (err0("Unexpected array"), NUL))
#define get_elem(t) (t->tag == LIST ? t->u.list : (Type *) (err0("Unexpected list"), Top))
#define get_object(t) (t->tag == OBJECT ? t->u.class->name : (char *) (err0("Unexpected object"), ""))
#define get_agent(t) (t->tag == AGENT ? t->u.class->name : (char *) (err0("Unexpected agent"), ""))
#define ref_class(t) (isclass(t) ? t->u.class->name : (char *) (err0("Invalid destination"), ""))
#define ref_object(t) (t->tag == OBJECT ? t->u.class->name : (char *) (err0("Bad object reference"), ""))
#define ref_dims(t) (t->tag == ARRAY ? t->u.array->dims : (Dim *) (err0("Bad array reference"), NUL))
typedef struct _File File;
typedef struct _Spec Spec;
typedef struct _Gene Gene;
typedef struct _Cond Cond;
typedef struct _Cst Cst;
typedef struct _Att Att;
typedef struct _Met Met;
typedef struct _Arg Arg;
typedef struct _Type Type;
typedef struct _Class Class;
typedef struct _Con Con;
typedef struct _Array Array;
typedef struct _Dim Dim;
typedef struct _Imp Imp;
typedef struct _Rule Rule;
typedef struct _Head Head;
typedef struct _Clu Clu;
typedef struct _Pred Pred;
typedef struct _Var Var;
typedef struct _Par Par;
typedef struct _Prop Prop;
typedef struct _Node Node;
typedef struct _Goal Goal;
struct _File {
char name[1024];
int line;
char *buf;
char *ptr;
};
struct _Spec {
char *name;
int soff;
int level;
int size;
Spec *base;
Gene *genes;
Cond *conds;
Cst *csts;
Att *atts;
Met *mets;
int mark;
Spec *next;
};
struct _Gene {
char *name;
int goff;
Gene *next;
};
struct _Cond {
char *name;
int coff;
Cond *next;
};
struct _Cst {
char *name;
Node *node;
Cst *next;
};
struct _Att {
char *name;
int aoff;
int level;
int prot;
Type *type;
Node *init;
Att *next;
};
struct _Met {
char *name;
int moff;
int level;
int prot;
Arg *args;
Met *next;
};
struct _Arg {
char *name;
int flow;
Type *type;
Arg *next;
};
struct _Type {
int tag;
union {
Array *array;
Type *list;
Class *class;
int meta;
} u;
};
struct _Class {
char *name;
Con *cons;
};
struct _Con {
Type *type;
Con *next;
};
struct _Array {
Type *item;
Dim *dims;
};
struct _Dim {
int size;
Dim *next;
};
struct _Imp {
char *name;
Spec *spec;
Goal *goal;
Rule *rules;
Imp *next;
};
struct _Rule {
Var *vars;
Head *head;
Clu *body;
Clu *tail;
Pred *last;
Rule *next;
};
struct _Head {
char *name;
int moff;
int prot;
Par *pars;
};
struct _Clu {
Pred *pred;
int step;
Clu *next;
};
struct _Pred {
int tag;
int moff;
Par *pars;
Node *dest;
Pred *next;
};
struct _Var {
char *name;
int voff;
int state;
int def;
int use;
Type *hout;
Type *bint;
Type *mint;
Var *next;
};
struct _Par {
int flow;
Node *node;
Par *next;
};
struct _Prop {
Node *node;
Prop *next;
};
struct _Node {
int tag;
Type *type;
union {
Node *p;
int i;
double f;
} this;
Node *that;
};
struct _Goal {
Att *atts;
Var *vars;
Clu *body;
};
extern Type *Top;
extern Type *Bot;
extern Type *Int;
extern Type *Real;
extern Type *Char;
extern Type *Condv;
extern Node *Izero;
extern Node *Rzero;
extern Node *Blank;
extern Node *Nil;
extern Node *Anon;
extern Node *Self;
extern Node *Site;
extern Spec *specs;
extern Imp *imps;
extern Goal *goal;
extern Att *Atts0;
extern char *fname;
extern int lineno;
extern int errono;
extern char errbuf[];
extern int atoi();
extern long atol();
extern double atof();
extern Spec *Spec_();
extern Gene *Gene_();
extern Cond *Cond_();
extern Cst *Cst_();
extern Att *Att_();
extern Met *Met_();
extern Arg *Arg_();
extern Type *Type_();
extern Class *Class_();
extern Con *Con_();
extern Array *Array_();
extern Dim *Dim_();
extern Imp *Imp_();
extern Rule *Rule_();
extern Head *Head_();
extern Clu *Clu_();
extern Pred *Pred_();
extern Var *Var_();
extern Par *Par_();
extern Prop *Prop_();
extern Node *Node_p();
extern Node *Node_i();
extern Node *Node_f();
extern Goal *Goal_();
extern Spec *find_spec();
extern Spec *find_base();
extern Gene *find_gene();
extern Cond *find_cond();
extern Cst *find_cst();
extern Att *find_att();
extern Met *find_met();
extern Arg *find_arg();
extern Imp *find_imp();
extern Head *find_head();
extern Var *find_var();
extern Spec *lookup_spec();
extern Spec *lookup_base();
extern Gene *lookup_gene();
extern Cond *lookup_cond();
extern Att *lookup_att();
extern Met *lookup_met();
extern Att *subs_ratts();
extern Arg *subs_args();
extern Type *subs_type();
extern Con *subs_cons();
extern Type *subs_meta();
extern Con *make_cons();
extern Att *next_atts();
extern int grab_size();
extern void update_vars();
extern void undo_vars();
extern void mark_var();
extern void check_bound();
extern void check_vars();
extern void check_lvar();
extern void check_var();
extern void check_lref();
extern void check_ref();
extern void check_relop();
extern void check_num();
extern void check_nil();
extern void check_index();
extern void check_size();
extern void check_dim();
extern void check_string();
extern void check_handle();
extern void check_name();
extern Type *sub_type();
extern Type *min_type();
extern int match_type();
extern int match_name();
extern int match_cons();
extern int match_dims();
extern int match_meta();
extern Pred *eval_relop();
extern Node *eval_arop();
extern Node *eval_uminus();
extern Node *eval_fun();
extern Node *eval_float();
extern int eval_cost();
extern Pred *apply_relop_c();
extern Pred *apply_relop_i();
extern Pred *apply_relop_f();
extern Node *apply_arop_i();
extern Node *apply_arop_f();
extern Node *apply_fun_i();
extern Node *apply_fun_f();
extern int len_props();
extern int len_pars();
extern Par *next_pars();
extern int match_pars();
extern int max_vars();
extern int in_node();
extern int in_pars();
extern int in_preds();
extern int in_clus();
extern int in_rules();
extern void print_node();
extern void print_tag();
extern void print_tags();
extern void print_type();
extern void print_types();
extern void print_dims();
extern void print_props();
extern int print_rpars();
extern void print_pars();
extern int print_rargs();
extern void print_vars();
extern void print_last();
extern int print_preds();
extern int print_clus();
extern void print_rules();
extern void print_atts();
extern void print_goal();
extern void print_spec();
extern void print_specs();
extern void print_imps();
extern void print_classes();
extern char *print_globals();
extern char *print_locals();
extern void print_main();
extern void point_error();
extern void line_error();
extern void track_line();
extern void lex_escape();
extern int lex_token();
extern void xxerror();
extern int xxlex();
extern void init_lex();
extern int xxparse();
extern void init_par();
extern void parse();
extern int read_file();
extern int write_file();
extern int new_include();
extern char *include();
extern void filter();
extern int pprocess();
extern void compile();
extern void main();